package cn.csg.iotplatform.module.system.dal.mysql.manufacturer;

import java.util.*;

import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csg.iotplatform.framework.mybatis.core.mapper.BaseMapperX;
import cn.csg.iotplatform.module.system.dal.dataobject.manufacturer.ManufacturerDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.csg.iotplatform.module.system.controller.admin.manufacturer.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 厂商信息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ManufacturerMapper extends BaseMapperX<ManufacturerDO> {

    default PageResult<ManufacturerDO> selectPage(ManufacturerPageReqVO reqVO) {
        LambdaQueryWrapperX<ManufacturerDO> queryWrapper = new LambdaQueryWrapperX<ManufacturerDO>()
                .likeIfPresent(ManufacturerDO::getManufacturerType, reqVO.getManufacturerType())
                .eqIfPresent(ManufacturerDO::getManufacturerNo, reqVO.getManufacturerNo())
                .likeIfPresent(ManufacturerDO::getManufacturerId, reqVO.getManufacturerId())
                .likeIfPresent(ManufacturerDO::getManufacturerShortName, reqVO.getManufacturerShortName())
                .likeIfPresent(ManufacturerDO::getUnifiedSocialCreditCode, reqVO.getUnifiedSocialCreditCode())
                .eqIfPresent(ManufacturerDO::getManufacturerUrl, reqVO.getManufacturerUrl())
                .eqIfPresent(ManufacturerDO::getServiceEmail, reqVO.getServiceEmail())
                .eqIfPresent(ManufacturerDO::getServiceTel, reqVO.getServiceTel())
                .eqIfPresent(ManufacturerDO::getBusinessCode, reqVO.getBusinessCode())
                .eqIfPresent(ManufacturerDO::getBusinessUrl, reqVO.getBusinessUrl())
                .eqIfPresent(ManufacturerDO::getLogo, reqVO.getLogo())
                .eqIfPresent(ManufacturerDO::getAuthStatus, reqVO.getAuthStatus())
                .eqIfPresent(ManufacturerDO::getProvince, reqVO.getProvince())
                .eqIfPresent(ManufacturerDO::getCity, reqVO.getCity())
                .eqIfPresent(ManufacturerDO::getArea, reqVO.getArea())
                .eqIfPresent(ManufacturerDO::getManufacturerAddress, reqVO.getManufacturerAddress())
                .eqIfPresent(ManufacturerDO::getManufacturerAddressDetail, reqVO.getManufacturerAddressDetail())
                .eqIfPresent(ManufacturerDO::getManufacturerUser, reqVO.getManufacturerUser())
                .eqIfPresent(ManufacturerDO::getManufacturerTel, reqVO.getManufacturerTel())
                .eqIfPresent(ManufacturerDO::getContactAddress, reqVO.getContactAddress())
                .eqIfPresent(ManufacturerDO::getContactEmail, reqVO.getContactEmail())
                .eqIfPresent(ManufacturerDO::getIntroduce, reqVO.getIntroduce())
                .eqIfPresent(ManufacturerDO::getNote, reqVO.getNote())
                .eqIfPresent(ManufacturerDO::getDataSource, reqVO.getDataSource())
                .eqIfPresent(ManufacturerDO::getEnablingStatus, reqVO.getEnablingStatus())
                .betweenIfPresent(ManufacturerDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ManufacturerDO::getUpdater, reqVO.getUpdater())
                .betweenIfPresent(ManufacturerDO::getUpdateTime, reqVO.getUpdateTime())
                .eqIfPresent(ManufacturerDO::getCreator, reqVO.getCreator())
                .orderByDesc(ManufacturerDO::getUpdateTime);
        if(reqVO != null && StringUtils.isNotBlank(reqVO.getManufacturerName())) {
            queryWrapper.and(wrapper -> wrapper.like(ManufacturerDO::getManufacturerName , reqVO.getManufacturerName()).or()
                    .like(ManufacturerDO::getManufacturerShortName ,reqVO.getManufacturerName()));
        }
        return selectPage(reqVO, queryWrapper);
    }

    List<ManufacturerDO> getSyncManufacturerList();

    void updateManufacturerSyncStatus(String id);

    String getGkConfig(String configKey);

    List<String> getAuthManu(@Param("ids") List<String> ids);
}